package com.terrynoya.fight.stateMachine.controllers
{
	import com.terrynoya.fight.char.Character;
	import com.terrynoya.fight.stateMachine.StateController;
	
	public class TargetState extends StateController
	{
		public function TargetState(name:String)
		{
			super(name);
		}
		
		override public function run(character:Character):void
		{
			var stateIdExist:Boolean = this.hasAttribute("value");
			if(!stateIdExist)
			{
				return;
			}
			
			var stateId:int = this.getAttributeAsInt("value");
			var targetId:int = this.getAttributeAsInt("id",int.MIN_VALUE);
			var targetList:Array = character.getTargets(targetId);
			for (var i:int = 0; i < targetList.length; i++) 
			{
				var target:Character = targetList[i];
				target.stateManager.foreignMachine = character.stateManager;
				target.stateManager.changeState(stateId);
			}
		}
	}
}